<template>
    <div id="JDJGPDF">
        <!-- <div class="content">
      <div class="list"> -->
        <van-form validate-first>
            <p class="subTitle"><span class="line"></span>鉴定基本信息</p>
            <div v-if="SHOWData">
                <!-- <van-field :readonly='isread' clickable name="picker" v-model="sexName" label="性别" placeholder="请选择性别" @click="ENUM.XB = true" /> -->
                <van-field :readonly="isread" v-model="SHOWData[0].F_GCMC" label="工程名称" placeholder="请填写工程名称" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_WTDW" label="委托单位" placeholder="请填写委托单位" />
                <!-- <van-field :readonly="isread" v-model="SHOWData[0].F_BGRQ" label="报告日期" placeholder="请填写报告日期" /> -->
                <van-field readonly clickable name="datetimePicker" :value="SHOWData[0].F_BGRQ" label="报告日期"
                    placeholder="请填写报告日期" @click="showPickerq1 = true" />
                <van-popup v-model="showPickerq1" position="bottom">
                    <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" @cancel="showPickerq1 = false"
                        @confirm="onConfirmRQ1" />
                </van-popup>
                <van-field :readonly="isread" v-model="SHOWData[0].F_JDGSMC" label="鉴定公司名称" placeholder="请填写鉴定公司名称" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_CKJDRY" label="查勘、鉴定人员" placeholder="请填写查勘、鉴定人员" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_BGBXR" label="报告编写人" placeholder="请填写报告编写人" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_SHR" label="审核人" placeholder="请填写审核人" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_PZR" label="批准人" placeholder="请填写批准人" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_DZ" label="地址" placeholder="请填写地址" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_DH" label="电话" placeholder="请填写电话" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_YB" label="邮编" placeholder="请填写邮编" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_CZ" label="传真" placeholder="请填写传真" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_BGBH" label="报告编号" placeholder="请填写报告编号" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_FWDZ" label="房屋地址" placeholder="请填写房屋地址" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_FWYT" label="房屋用途" placeholder="请填写房屋用途" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_JZNF" label="建造年份" placeholder="请填写建造年份" />
                <!-- <van-field
              :readonly="isread"
              v-model="SHOWData[0].F_JGLX"
              label="结构类型"
              placeholder="请填写结构类型"
            /> -->
                <van-field readonly clickable name="picker" :value="SHOWData[0].F_JGLX | inUseName(ENUM.JGLXARR)"
                    label="结构类型" placeholder="请填写结构类型" @click="showPickerC = true"
                    :rules="[{ required: true, message: '结构类型' }]" />
                <van-popup v-model="showPickerC" position="bottom" get-container="#popup">
                    <van-picker show-toolbar :columns="CityColumns" value-key="DICNAME" @confirm="onConfirmTown"
                        @cancel="showPickerC = false" />
                </van-popup>
                <van-field :readonly="isread" v-model="SHOWData[0].F_JZMJ" label="建筑面积(㎡)" placeholder="请填写建筑面积" />

                <van-field :readonly="isread" v-model="SHOWData[0].F_ZDMJ" label="占地面积(㎡)" placeholder="请填写占地面积" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_FWCX" label="房屋朝向" placeholder="请填写房屋朝向" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_FWCS" label="层数" placeholder="请填写层数" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_PMJG" label="平面结构" placeholder="请填写平面结构" />
                <!-- <van-field
              :readonly="isread"
              v-model="SHOWData[0].F_TCSJ"
              label="调查时间"
              placeholder="请填写调查时间"
            /> -->
                <van-field readonly clickable name="datetimePicker" :value="SHOWData[0].F_TCSJ" label="填写日期"
                    placeholder="请填写日期" @click="showPickerq2 = true" />
                <van-popup v-model="showPickerq2" position="bottom">
                    <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" @cancel="showPickerq2 = false"
                        @confirm="onConfirmRQ2" />
                </van-popup>
                <van-field :readonly="isread" v-model="SHOWData[0].F_CZTX" label="承重体系" placeholder="请填写承重体系" />

                <van-field :readonly="isread" v-model="SHOWData[0].F_FMXS" label="房面形式" placeholder="请填写房面形式" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_CKQK" label="查勘情况" placeholder="请填写查勘情况" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_JL" label="结论" placeholder="请填写结论" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_CLJY" label="处理建议" placeholder="请填写处理建议" />
                <van-field :readonly="isread" v-model="SHOWData[0].F_DXRQ" label="大写日期" placeholder="请填写大写日期" />
                <div v-for="(item, index) in ImgData" :key="index + 'ImgData'">
                    <p class="subTitle"><span class="line"></span>{{ item.name }}</p>
                    <van-uploader style="margin-top: 8px" @click-upload="getList(item)" :after-read="afterRead"
                        :before-delete="delectFile" v-model="item.fileList"
                         multiple />
                </div>
            </div>
        </van-form>
    </div>
</template>
<script>
import {
    QuerySignCallback,
    dataTransFile,
    FileServerProxy,
    DelectFile,
    dataTransFilePreview
} from "../../utils/api";
import { v4 as uuidv4 } from "uuid";
export default {
    data() {
        return {
            hideMap: true,
            isread: false,
            fileLists: [],
            MapUrl: "",
            NYD: "",
            DL: "",
            JFLX: "",
            className: "",
            showPicker1: false,
            showPicker2: false,
            showPicker3: false,
            isShowTK: false,
            isShowCH: false,
            ImgData: [
                {
                    name: "房屋外立面",
                    groupGuid: "e7301a30-a811-48db-8576-b5014cec553a",
                    fileList: [],
                },
                {
                    name: "现场照片",
                    groupGuid: "16399a03-49e2-407a-8c31-f364b4aab2c6",
                    fileList: [],
                },
                {
                    name: "现场照片2",
                    groupGuid: "25f24d78-5483-423e-a137-21bd15fe2d08",
                    fileList: [],
                },
            ],
            //存储需要传给treeSelect组件的值
            SaveCHDW: [],
            SaveTKDW: [],
            SHOWData: [{
                F_BGRQ: "",
                F_CKQK: "",
                F_BGBH:"",
                F_DZ: "",
                F_FWDZ:"",
                F_GCMC: "",
                F_JZMJ: "",
                F_TCSJ: "",
                F_WTDW: "",
                F_ZDMJ: "",
                F_DH:"",
                F_YB:"",
                F_CZ:""
            }],
            showPickerq: false,
            showPickerq1: false,
            showPickerq2: false,
            minDate: new Date(2020, 0, 1),
            maxDate: new Date(2025, 10, 1),
            currentDate: new Date(),
            fileList: [],
            //踏勘单位
            TKDW: [],
            //测绘单位
            CHDW: [],
            valueZhen: "",
            valueZhen1: "",
            TownColumns: [],
            TownColumns1: [],
            showPickerT1: false,
            showPickerT: false,
            groupGuids: "",
            Canshu: 0,
            ENUM: {
                XB: false,
                XBARR: [],
                SF: false,
                SF1: false,
                SF2: false,
                SFARR: [],
                SFARR1: [],
                SFARR2: [],
                NYD: false,
                NYDARR: [],
                JFLX: false,
                JFLXARR: [],
                YDLX: false,
                YDLXARR: [],
                JGLX: false,
                JGLXARR: [],
                WSCLFS: false,
                WSCLFSARR: [],
            },
            isSaveFile: false,
            sexName: "",
            showPickerC: false,
            JGXSKJJG: "",
            CityColumns: [],
            rowGuid: "",
            dataRowguid: "",
            //存公司地址
            NewData: []
        };
    },
    props: {
        row: Object,
        rowDataNew: Object.rowDataNew
    },
    watch: {
        rowDataNew() {
            if (this.rowDataNew && this.rowDataNew.ROW_GUID) {
                this.rowGuid = this.rowDataNew.ROW_GUID;
            } else {
                this.rowGuid = this.newGuid()
            }
            this.getFile();
            this.getData();
            this.getJFLYOpenDataView();
            if (this.$parent.formData.JDJG) {
                this.SHOWData[0].F_JDGSMC = this.$parent.formData.JDJG
            }
            // this.getFile();
            this.getGsDz()
        },
    },
    filters: {
        inUseName: function (msg, data) {
            let name = "";
            data.forEach((item) => {
                if (item.DICID == msg) {
                    name = item.DICNAME;
                }
            });
            return name;
        },
    },
    mounted() {
        window.sessionStorage.setItem("ROW_GUID1", JSON.parse(this.$route.query.data).ROW_GUID);
        this.getEnum("b65d1943-66f4-49b1-b759-cd9f079dc0d3")
        this.SHOWData[0].F_CKQK = "详见农村房屋结构安全排查登记表"
        // this.getData();
        this.getJFLYOpenDataView();

        if (ZWJSBridge) {
            ZWJSBridge.setTitle({
                title: "鉴定报告",
            })
                .then((res) => {
                })
                .catch((err) => {
                });
        }
    },
    methods: {
        onConfirmTown(value) {
            this.JGXSKJJG = value.DICNAME;
            this.SHOWData[0].F_JGLX = value.DICID;
            this.showPickerC = false;
        },
        getJFLYOpenDataView: async function () {
            this.CityColumns = [];
            let dataGuid = "b65d1943-66f4-49b1-b759-cd9f079dc0d3";
            let searchObject = [];
            let token = window.localStorage.getItem("token");
            let params = {
                accessCode: "688bd3883572440a859dfd8ba9194e7b",

                cityCode: window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "441300000000",
                params: {
                    dataguid: dataGuid,
                    searchObject: searchObject,
                    token: token,
                },
            };
            const res = await QuerySignCallback(params);
            this.CityColumns = eval("(" + res.data.data + ")").Data;
        },
        //回显数据1
        //点击列表签订合同打开前端写的合同界面，先调用查询接口(接口1),判断如果有数据，就回显查询接口的合同内容。同时点击保存合同信息因调用修改接口(接口2)，如果没有数据就回显接口（接口3）的数据，
        //同时保存应掉新增接口（接口4）
        //接口1
        onConfirmRQ1(val) {
            let year = val.getFullYear();
            let month = val.getMonth() + 1;
            let day = val.getDate();
            let hour = val.getHours();
            let minute = val.getMinutes();
            if (month >= 1 && month <= 9) {
                month = `0${month}`;
            }
            if (day >= 1 && day <= 9) {
                day = `0${day}`;
            }
            if (hour >= 0 && hour <= 9) {
                hour = `0${hour}`;
            }
            if (minute >= 0 && minute <= 9) {
                minute = `0${minute}`;
            }
            this.className = "timeClass";
            ;
            this.SHOWData[0].F_BGRQ = `${year}-${month}-${day}`;
            this.showPickerq1 = false;
        },
        onConfirmRQ2(val) {
            let year = val.getFullYear();
            let month = val.getMonth() + 1;
            let day = val.getDate();
            let hour = val.getHours();
            let minute = val.getMinutes();
            if (month >= 1 && month <= 9) {
                month = `0${month}`;
            }
            if (day >= 1 && day <= 9) {
                day = `0${day}`;
            }
            if (hour >= 0 && hour <= 9) {
                hour = `0${hour}`;
            }
            if (minute >= 0 && minute <= 9) {
                minute = `0${minute}`;
            }
            this.className = "timeClass";
            this.SHOWData[0].F_TCSJ = `${year}-${month}-${day}`;
            this.showPickerq2 = false;
        },

        newGuid(format) {
            //表示全局唯一标识符 (GUID)。
            function Guid(g) {
                var arr = new Array(); //存放32位数值的数组
                if (typeof g == "string") {
                    //如果构造函数的参数为字符串
                    InitByString(arr, g);
                } else {
                    InitByOther(arr);
                }
                //返回 Guid 类的此实例值的 String 表示形式。
                this.ToString = function (format) {
                    if (typeof format == "string") {
                        if (
                            format == "N" ||
                            format == "D" ||
                            format == "B" ||
                            format == "P"
                        ) {
                            return ToStringWithFormat(arr, format);
                        } else {
                            return ToStringWithFormat(arr, "D");
                        }
                    } else {
                        return ToStringWithFormat(arr, "D");
                    }
                }
            }
        },
        getEnum: async function (viewID) {
            let _this = this;
            let params = {
                dataguid: viewID,
                searchObject: JSON.stringify([]),
                token: window.localStorage.getItem('token')
            }
            let params1 = {
                accessCode: '688bd3883572440a859dfd8ba9194e7b',
                cityCode: window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "",
                params: params
            }
            const res = await QuerySignCallback(params1)
            let data = eval('(' + res.data.data + ')').Data
            switch (viewID) {
                case "b65d1943-66f4-49b1-b759-cd9f079dc0d3":
                    this.ENUM.JGLXARR = data;
                    break;
                default:
                    break;
            }
        },
        onConfirmTown(value) {
            this.JGXSKJJG = value.DICNAME;
            this.SHOWData[0].F_JGLX = value.DICID;
            this.showPickerC = false;
        },
        getJFLYOpenDataView: async function () {
            this.CityColumns = [];
            let dataGuid = "b65d1943-66f4-49b1-b759-cd9f079dc0d3";
            let searchObject = [];
            let token = window.localStorage.getItem("token");
            let params = {
                accessCode: "688bd3883572440a859dfd8ba9194e7b",
                cityCode: window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "",
                params: {
                    dataguid: dataGuid,
                    searchObject: searchObject,
                    token: token,
                },
            };
            const res = await QuerySignCallback(params);
            this.CityColumns = eval("(" + res.data.data + ")").Data;
        },
        //回显数据1
        //点击列表签订合同打开前端写的合同界面，先调用查询接口(接口1),判断如果有数据，就回显查询接口的合同内容。同时点击保存合同信息因调用修改接口(接口2)，如果没有数据就回显接口（接口3）的数据，
        //同时保存应掉新增接口（接口4）
        //接口1
        onConfirmRQ1(val) {
            let year = val.getFullYear();
            let month = val.getMonth() + 1;
            let day = val.getDate();
            let hour = val.getHours();
            let minute = val.getMinutes();
            if (month >= 1 && month <= 9) {
                month = `0${month}`;
            }
            if (day >= 1 && day <= 9) {
                day = `0${day}`;
            }
            if (hour >= 0 && hour <= 9) {
                hour = `0${hour}`;
            }
            if (minute >= 0 && minute <= 9) {
                minute = `0${minute}`;
            }
            this.className = "timeClass";
            this.SHOWData[0].F_BGRQ = `${year}-${month}-${day}`;
            this.showPickerq1 = false;
        },
        onConfirmRQ2(val) {
            let year = val.getFullYear();
            let month = val.getMonth() + 1;
            let day = val.getDate();
            let hour = val.getHours();
            let minute = val.getMinutes();
            if (month >= 1 && month <= 9) {
                month = `0${month}`;
            }
            if (day >= 1 && day <= 9) {
                day = `0${day}`;
            }
            if (hour >= 0 && hour <= 9) {
                hour = `0${hour}`;
            }
            if (minute >= 0 && minute <= 9) {
                minute = `0${minute}`;
            }
            this.className = "timeClass";
            this.SHOWData[0].F_TCSJ = `${year}-${month}-${day}`;
            this.showPickerq2 = false;
        },
        inUseName1(msg, data) {
            let name = ''
            data.forEach(item => {
                if (item.CITYCODE == msg) {
                    name = item.CITYNAME
                }
            })
            return name
        },
        getData: async function () {
            var dataGuid = "";
            var OPTYPE = "";
            if (this.row.NODE_GUID === '{27EE0E9F-607B-4D25-8934-3693F950C095}' || this.row.NODE_GUID === '{7A93D2DC-D4B9-4E6A-8DC6-4C2FDFBB9D45}'||this.row.NODE_GUID === '{B4FCC404-5D84-4F9A-B5A2-243ECE2FB244}') {
                dataGuid = "68cd7dca-5812-4e11-9201-ff10b7f96d2f"
                OPTYPE = 2
            }
            else {
                dataGuid = "2ffd285d-f8b9-4b94-841d-ac9d7e0321e6"
                OPTYPE = 1
            }
            console.log(this.rowGuid, 'jhjhjhj')
            var searchObjects = JSON.stringify([
                {
                    field: "TO_ROW_GUID",
                    value: this.rowGuid,
                    operator: "=",
                },
            ]);
            let params = {
                accessCode: "688bd3883572440a859dfd8ba9194e7b",
                cityCode: window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "",
                params: {
                    dataguid: dataGuid,
                    searchObject: searchObjects,
                },
            };
            const res = await QuerySignCallback(params);
            console.log(JSON.parse(res.data.data).Data, '小何6')
            if (JSON.parse(res.data.data).Data.length != 0) {
                // alert(1)
                this.Canshu = 0;
                //代表有数据
                this.dataRowguid = JSON.parse(res.data.data).Data[0].ROW_GUID;
                this.SHOWData = [];
                this.SHOWData.push(JSON.parse(res.data.data).Data[0]);

            } else {
                this.dataRowguid = this.newGuid();
                this.Canshu = 1;
                if (this.NewData.length > 0) {
                    for(var i in this.NewData[0]){
                        this.SHOWData[0][i] = this.NewData[0][i]
                    }
                    if (this.$parent.formData.JDBGBH) {
                        this.SHOWData[0].F_BGBH = this.$parent.formData.JDBGBH
                    }
                    if (this.$parent.formData.FWDZ) {
                        this.SHOWData[0].F_FWDZ = this.$parent.formData.FWDZ
                    }
                } else {
                    setTimeout(() => {
                        let rowData = this.row
                        if (rowData) {
                            if (rowData.XCITY && this.NewData.length == 0) {
                                console.log(this.$parent.XianColumns)
                                this.SHOWData[0].F_GCMC = this.inUseName1(rowData.XCITY, this.$parent.XianColumns) + '·' + this.inUseName1(rowData.ZCITY, this.$parent.TownColumns) + '·' + this.inUseName1(rowData.CCITY, this.$parent.CunColumns) + '·' + rowData.SQR
                            }
                            console.log(rowData)
                            if (rowData.KNLX == 5) {
                                this.SHOWData[0].F_JDGSMC = this.$parent.formData.JDJG
                            }
                            if (rowData.SQR) {
                                this.SHOWData[0].F_WTDW = rowData.SQR
                            }
                            // if (rowData.JDSJ) {
                            //
                            //   this.SHOWData[0].F_BGRQ = rowData.JDSJ
                            // }
                            this.SHOWData[0].F_BGRQ = this.getDate().split(" ")[0]
                            if (rowData.JDJG) {
                                this.SHOWData[0].F_JDGSMC = rowData.JDJG
                            }
                            if (rowData.FWDZ && this.NewData.length == 0) {
                                this.SHOWData[0].F_DZ = rowData.FWDZ
                            }
                            if (rowData.JDBGBH) {
                                debugger
                                this.SHOWData[0].F_BGBH = rowData.JDBGBH
                            }
                            if (this.getDate(true)) {
                                this.SHOWData[0].F_TCSJ = this.getDate(true)
                            }
                            if (rowData.JZMJ) {
                                this.SHOWData[0].F_JZMJ = rowData.JZMJ
                            }
                            if (rowData.ZJDMJ) {
                                this.SHOWData[0].F_ZDMJ = rowData.ZJDMJ
                            }
                            console.log(this.$parent.formData.JDBGBH, '小何')
                            if (this.$parent.formData.JDBGBH) {
                                this.SHOWData[0].F_BGBH = this.$parent.formData.JDBGBH
                            }
                            if (this.$parent.formData.FWDZ) {
                                this.SHOWData[0].F_FWDZ = this.$parent.formData.FWDZ
                            }
                        }
                    }, 1000)
                }
                //督办环节 部分字段赋值
                if (this.row.WF_GUID == '{AFA7FC7F-BDBD-46EA-ABD2-EEF0766096D2}') {
                    let paer1 = {
                        procName: "up_processusername",
                        dtParams: JSON.stringify([
                            { I_USERID: "'" + this.row.ROW_GUID + "'", I_TYPE: 32 },
                        ]),
                        token: window.localStorage.getItem("token"),
                    };
                    let procNamesk1 = {
                        accessCode: "69db6bece3a7480592e2ec753d1e335e",
                        cityCode: window.localStorage.getItem("citycode")
                            ? window.localStorage.getItem("citycode")
                            : "441300000000",
                        params: paer1,
                    };
                    const reskh1 = await FileServerProxy(procNamesk1);
                    let data1 = eval('(' + reskh1.data.data + ')').Data
                    if (data1.length > 0) {
                        for (var i in data1[0]) {
                            this.SHOWData[0][i] = data1[0][i]
                        }
                    }
                    setTimeout(()=>{
                       if (this.$parent.formData.JDBGBH) {
                        this.SHOWData[0].F_BGBH = this.$parent.formData.JDBGBH
                    }
                    if (this.$parent.formData.FWDZ) {
                        this.SHOWData[0].F_FWDZ = this.$parent.formData.FWDZ
                    }
                    },1000)
                }

            }
            console.log(this.$parent.formData.JDBGBH, '小何')
            if (this.$parent.formData.JDBGBH) {
                this.SHOWData[0].F_BGBH = this.$parent.formData.JDBGBH
            }
            if(this.$parent.formData.FWDZ){
               this.SHOWData[0].F_FWDZ = this.$parent.formData.FWDZ
            }
            this.SHOWData[0].F_CKQK = "详见农村房屋结构安全排查登记表"
            this.SHOWData[0].F_BGRQ = this.SHOWData[0].F_BGRQ ? this.SHOWData[0].F_BGRQ.split(" ")[0] : '';
            this.SHOWData[0].F_TCSJ = this.SHOWData[0].F_TCSJ ? this.SHOWData[0].F_TCSJ.split(" ")[0] : '';
        },
        newGuid(format) {
            //表示全局唯一标识符 (GUID)。
            function Guid(g) {
                var arr = new Array(); //存放32位数值的数组
                if (typeof g == "string") {
                    //如果构造函数的参数为字符串
                    InitByString(arr, g);
                } else {
                    InitByOther(arr);
                }
                //返回 Guid 类的此实例值的 String 表示形式。
                this.ToString = function (format) {
                    if (typeof format == "string") {
                        if (
                            format == "N" ||
                            format == "D" ||
                            format == "B" ||
                            format == "P"
                        ) {
                            return ToStringWithFormat(arr, format);
                        } else {
                            return ToStringWithFormat(arr, "D");
                        }
                    } else {
                        return ToStringWithFormat(arr, "D");
                    }
                };

                //由字符串加载
                function InitByString(arr, g) {
                    g = g.replace(/\{|\(|\)|\}|-/g, "");
                    g = g.toLowerCase();
                    if (g.length != 32 || g.search(/[^0-9,a-f]/i) != -1) {
                        InitByOther(arr);
                    } else {
                        for (var i = 0; i < g.length; i++) {
                            arr.push(g[i]);
                        }
                    }
                }

                //由其他类型加载
                function InitByOther(arr) {
                    // var i = 32;
                    // while (i--) {
                    //     arr.push("0");
                    // }

                    var i = 32;
                    while (i--) {
                        arr.push(Math.floor(Math.random() * 16.0).toString(16));
                    }
                }

                /*
                      根据所提供的格式说明符，返回此 Guid 实例值的 String 表示形式。
                      N  32 位： xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                      D  由连字符分隔的 32 位数字 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
                      B  括在大括号中、由连字符分隔的 32 位数字：{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
                      P  括在圆括号中、由连字符分隔的 32 位数字：(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
                      */

                //增加一个标识能区分开这个guid是不是由前端生成的
                function ToStringWithFormat(arr, format) {
                    switch (format) {
                        case "N":
                            return arr.toString().replace(/,/g, "");
                        case "D":
                            var str =
                                arr.slice(0, 8) +
                                "-1203" +
                                "-" +
                                arr.slice(12, 16) +
                                "-" +
                                arr.slice(16, 20) +
                                "-" +
                                arr.slice(20, 32);
                            str = str.replace(/,/g, "");
                            return str;
                        case "B":
                            var str = ToStringWithFormat(arr, "D");
                            str = "{" + str + "}";
                            return str;
                        case "P":
                            var str = ToStringWithFormat(arr, "D");
                            str = "(" + str + ")";
                            return str;
                        default:
                            return new Guid();
                    }
                }

                return this.ToString();
            }

            var g = new Guid();
            return g.ToString(format);
        },
        base64ImgtoFile(dataurl, filename = "file") {
            let arr = dataurl.split(",");
            let mime = arr[0].match(/:(.*?);/)[1];
            let suffix = mime.split("/")[1];
            let bstr = atob(arr[1]);
            let n = bstr.length;
            let u8arr = new Uint8Array(n);
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n);
            }
            return new File([u8arr], `${filename}.${suffix}`, {
                type: mime,
            });
        },
        getNowTime: function () {
            let dateTime;
            let yy = new Date().getFullYear();
            let mm =
                new Date().getMonth() + 1 < 10
                    ? "0" + (new Date().getMonth() + 1)
                    : new Date().getMonth() + 1;
            let dd =
                new Date().getDate() < 10
                    ? "0" + new Date().getDate()
                    : new Date().getDate();
            let hh = new Date().getHours();
            let mf =
                new Date().getMinutes() < 10
                    ? "0" + new Date().getMinutes()
                    : new Date().getMinutes();
            let ss =
                new Date().getSeconds() < 10
                    ? "0" + new Date().getSeconds()
                    : new Date().getSeconds();
            dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
            return dateTime;
        },
        getFile: async function () {
          this.ImgData.forEach((items) => {
            items.fileList = []
          })
            let groupGuid = [];
            this.ImgData.forEach((item) => {
                groupGuid.push(item.groupGuid);
            });
            let params = {
                accessCode: "1fdcbce42c6d4748a020feba618d54b8",
                cityCode: window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "",
                params: {
                    groupGuid: groupGuid.join(","),
                    toRowGuid: this.rowGuid,
                    token: window.localStorage.getItem("token"),
                },
            };
            const res = await FileServerProxy(params);
            let data = JSON.parse(res.data.data).FilesInfo;
            if (data) {
                data.forEach((element) => {
                    this.ImgData.forEach((items) => {
                        if (element.GROUPGUID == items.groupGuid) {
                            this.getFileUrl(element, items);
                            // element["isImage"] = true;
                            // element["url"] =
                            //     window.g.BaseURL +
                            //     "FileServer/api/Preview?token=" +
                            //     window.localStorage.getItem("token") +
                            //     "&" +
                            //     "fileGuid=" +
                            //     encodeURIComponent(element.ROW_GUID);
                            // items.fileList.push(element);
                        }
                    });
                });
            }
        },
        //获取附件文件流
        getFileUrl: async function (element, item) {
            let formData = new FormData();
            formData.append("accessCode", "98bcf528966e48ce896a8b3fd02d45d5");
            formData.append(
                "cityCode",
                window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "441300000000"
            );
            formData.append(
                "paramStr",
                JSON.stringify({
                    fileGuid: element.ROW_GUID,
                })
            );
            let response = await dataTransFilePreview(formData);
            if (response) {
              // item.fileList = []
                var img = new Blob([new Int8Array(response.data, 0)], {
                    type: response.headers["content-type"],
                }); //type类型可自定义
                element["isImage"] = true;
                element["url"] = window.URL.createObjectURL(img);
                item.fileList.push(element);
                console.log(item.fileList)
            }
            console.log(response)

        },
        getGsDz: async function () {
            let I_TYPE = 25
            //判断当前环节是否为困难户
            if(this.row.WF_GUID == '{B1D50CB5-FA5D-4A07-93F6-D66543EB2916}'){
                I_TYPE = 36
            }
            let paer = {
                procName: "up_processusername",
                dtParams: JSON.stringify([
                    { I_USERID: "'" + this.row.ROW_GUID + "'", I_TYPE: I_TYPE },
                ]),
                token: window.localStorage.getItem("token"),
            };
            let procNamesk = {
                accessCode: "69db6bece3a7480592e2ec753d1e335e",
                cityCode: window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "441300000000",
                params: paer,
            };
            const res = await FileServerProxy(procNamesk);
            this.NewData = JSON.parse(res.data.data).Data
        },
        // 保存
        save: async function (type) {

            var dataGuid = "";
            var OPTYPE = "";
            if (this.row.NODE_GUID === '{27EE0E9F-607B-4D25-8934-3693F950C095}' || this.row.NODE_GUID === '{7A93D2DC-D4B9-4E6A-8DC6-4C2FDFBB9D45}') {
                dataGuid = "68cd7dca-5812-4e11-9201-ff10b7f96d2f"
                OPTYPE = 2
            }
            else if(this.row.NODE_GUID === '{B4FCC404-5D84-4F9A-B5A2-243ECE2FB244}'){
                dataGuid = "68cd7dca-5812-4e11-9201-ff10b7f96d2f"
                OPTYPE = 2
            }
            else {
                dataGuid = "2ffd285d-f8b9-4b94-841d-ac9d7e0321e6"
                OPTYPE = 1
            }
            if (this.Canshu == 1) {

                //新增
                // let uuid = uuidv4()
                this.SHOWData[0].ROW_GUID = this.dataRowguid; //this.$route.query.data.ROW_GUID;
                this.SHOWData[0].TO_ROW_GUID = this.rowGuid;
                this.SHOWData[0].OPTYPE = OPTYPE;
                //delete this.SHOWData[0].PKID;
                var accessCode = "00b87f486f8b11ecacdb8c8caa46b312";
            } else {
                //修改
                var accessCode = "77ad6c1591e54d4fbc45ecc90374a2a2";
                this.SHOWData[0].ROW_GUID = this.dataRowguid;
            }
            let params = {
                accessCode: accessCode,
                cityCode: window.localStorage.getItem("citycode")
                    ? window.localStorage.getItem("citycode")
                    : "441300000000",
                params: {
                    dataguid: dataGuid,
                    strParams: JSON.stringify(this.SHOWData),
                },
            };
            const res = await QuerySignCallback(params);
            if (type != '1') {
                if (JSON.parse(res.data.data).Success) {
                    this.$toast.success("保存成功");
                    this.getData()
                } else {
                    this.$toast.fail("保存失败");
                }
            }
        },
        CheckIsAndroid() {
            var browser = {
                versions: (function () {
                    var u = navigator.userAgent,
                        app = navigator.appVersion;
                    return {
                        //移动终端浏览器版本信息
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf("Android") > -1 || u.indexOf("Linux") > -1, //android终端或uc浏览器 //u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
                        iPhone: u.indexOf("iPhone") > -1, //是否为iPhone或者QQHD浏览器
                        iPad: u.indexOf("iPad") > -1, //是否iPad
                    };
                })(),
            };
            if (browser.versions.android) return true;
            return false;
        },
        //预览合同
        GotoPff() {
            // this.$router.push(
            //     {
            //       path:"./viewPDF",
            //       query:{
            //         data:`https://nfzjszlb.jst.zj.gov.cn/PrintServer/api/PreviewWordRpt?groupGuid=%7B4CD6F0FC-AC91-430B-B838-70DBABE0F603%7D&toRowGuid=${this.SHOWData[0].ROW_GUID}&dataGuid=2ffd285d-f8b9-4b94-841d-ac9d7e0321e6`
            //       }
            //     }
            //   )
            if (this.CheckIsAndroid()) {
                this.$router.push({
                    path: "./viewPDF",
                    query: {
                        data:
                            "https://nfzjszlb.jst.zj.gov.cn/PrintServer/api/PreviewWordRpt?groupGuid=%7B4CD6F0FC-AC91-430B-B838-70DBABE0F603%7D&toRowGuid=" +
                            this.rowGuid +
                            "&dataGuid=2ffd285d-f8b9-4b94-841d-ac9d7e0321e6",
                    },
                });
            } else {
                ZWJSBridge.openLink({
                    url:
                        "https://nfzjszlb.jst.zj.gov.cn/PrintServer/api/PreviewWordRpt?groupGuid=%7B4CD6F0FC-AC91-430B-B838-70DBABE0F603%7D&toRowGuid=" +
                        this.SHOWData[0].ROW_GUID +
                        "&dataGuid=2ffd285d-f8b9-4b94-841d-ac9d7e0321e6",
                })
                    .then((res) => {
                    })
                    .catch((err) => {
                        window.open(
                            `https://nfzjszlb.jst.zj.gov.cn/PrintServer/api/PreviewWordRpt?groupGuid=%7B4CD6F0FC-AC91-430B-B838-70DBABE0F603%7D&toRowGuid=${this.SHOWData[0].ROW_GUID}&dataGuid=2ffd285d-f8b9-4b94-841d-ac9d7e0321e6`
                        );
                    });
            }
        },
        //获取相关材料
        getList(data) {
            this.groupGuids = data;
        },
        lookFile(item) {
            let url =
                window.g.BaseURL +
                "FileServer/api/Preview?token=" +
                window.localStorage.getItem("token") +
                "&" +
                "fileGuid=" +
                encodeURIComponent(item.ROW_GUID);
            if (ZWJSBridge) {
                ZWJSBridge.openLink({
                    url: url,
                })
                    .then((res) => {
                    })
                    .catch((err) => {
                        window.open(url);
                    });
            }
        },
        //相关材料
        afterRead(file) {
            // 此时可以自行将文件上传至服务器
            // this.getFileServerUpload(file.file);
            if (Array.isArray(file)) {
                file.forEach((item, index) => {
                    this.getFileServerUpload(item.file);
                })
            } else {
                this.getFileServerUpload(file.file);
            }
        },
        blobToImg(blob) {
            return new Promise((resolve, reject) => {
                //
                let reader = new FileReader();
                reader.addEventListener("load", () => {
                    let img = new Image();
                    img.src = reader.result;
                    img.addEventListener("load", () => resolve(img));
                });
                reader.readAsDataURL(blob);
            });
        },
        getList(item) {
            this.groupGuids = item.groupGuid;
        },
        getFileServerUpload: async function (file) {
            let data = {
                toRowGuid: this.rowGuid,
                groupGuid: this.groupGuids,
                token: window.localStorage.getItem("token"),
            };
            let formData = new FormData();
            formData.append("file", file);
            formData.append("accessCode", "7a3fc061c866434b8475d3775c9ddcea");
            formData.append("cityCode", window.localStorage.getItem("citycode")
                ? window.localStorage.getItem("citycode")
                : "");
            formData.append("paramStr", JSON.stringify(data));
            const res = await dataTransFile(formData);
            let data1 = JSON.parse(res.data.data).FileList;
            this.fileGuid = data1[0].FILEGUID;
            if (data1[0].FILEGUID) {
                this.$toast.success("上传成功!");
            }
            if (res.data.Success == true) {
                this.$toast.success("上传成功!");
            }
        },
        delectFile: async function (file) {
            let fileguid = "";
            if (file.ROW_GUID) {
                fileguid = file.ROW_GUID;
            } else {
                fileguid = this.fileGuid;
            }
            if (fileguid) {
                let params = {
                    accessCode: "ce9b691634de4ebca68dc5bb638d07f4",
                    cityCode: window.localStorage.getItem("citycode")
                        ? window.localStorage.getItem("citycode")
                        : "441300000000",
                    params: {
                        fileGuid: fileguid,
                        token: window.localStorage.getItem("token"),
                    },
                };
                const res = await FileServerProxy(params);
                let data = JSON.parse(res.data.data).Success;
                if (data) {
                    this.$toast.success("删除成功!");
                }
            }
        },
    }
}
</script>
<style lang="scss">
#JDJGPDF {
    .subTitle {
        color: #3f8ffc;
        height: 40px;
        line-height: 40px;
        font-size: 16px;
    }

    .van-field {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        border-bottom: 1px solid #d2d2d2;
    }
}
</style>
